package cn.meibang.aggragation.meibanguserandclient.controller;

import cn.apestar.core.base.BaseMessage;
import cn.meibang.meibanguserandclient.api.IMeibangUserAndClientAPIService;
import cn.meibang.meibanguserandclient.provider.request.ListMeibangUserAndClientRequest;
import cn.meibang.meibanguserandclient.provider.request.MeibangUserAndClientRequest;
import cn.meibang.meibanguserandclient.provider.response.MeibangUserAndClientResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 业务管理客 <br>
 * 详细说明.
 * <p>
 *
 * @author yudw
 * @version 1.0
 */
@RestController @RequestMapping("/meibangUserAndClient")
public class MeibangUserAndClientController {

    private Logger logger = LoggerFactory.getLogger(MeibangUserAndClientController.class);

    @Autowired private IMeibangUserAndClientAPIService meibangUserAndClientService;

    /**
     * 新增业务管理客
     *
     * @param request
     */
    @RequestMapping(value = "/addorUpdate", method = RequestMethod.POST) public Object create(
        @RequestBody @Valid MeibangUserAndClientRequest request) {
        meibangUserAndClientService.addorUpdate(request);
        return new BaseMessage();
    }

    /**
     * 删除业务管理客
     *
     * @param id
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public Object del(
        @PathVariable("id") Long id) {
        meibangUserAndClientService.del(id);
        return new BaseMessage();
    }

    /**
     * 查询业务管理客
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/lisForPage", method = RequestMethod.POST)
    public List<MeibangUserAndClientResponse> lisForPage(
        @RequestBody ListMeibangUserAndClientRequest request) {
        List list = meibangUserAndClientService.lisForPage(request);
        return list;
    }

    /**
     * 查询业务管理客
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public List<MeibangUserAndClientResponse> list(
        @RequestBody MeibangUserAndClientRequest request) {
        List list = meibangUserAndClientService.list(request);
        return list;
    }

    /**
     * 查询业务管理客明细
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public MeibangUserAndClientResponse get(@PathVariable("id") Long id) {
        MeibangUserAndClientRequest request = new MeibangUserAndClientRequest();
        List<MeibangUserAndClientResponse> list = meibangUserAndClientService.list(request);
        if (list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }
}